package org.db2.project.airline.service;

import org.db2.project.airline.dao.DAOException;
import org.db2.project.airline.dao.FlightClassTypeDAO;
import org.db2.project.airline.dao.impl.HibernateFlightClassTypeDAO;
import org.db2.project.airline.model.FlightClassType;
import org.db2.project.airline.utils.HibernateHelper;

import java.util.List;

/**
 *
 */
public class FlightClassTypeService {

    private final FlightClassTypeDAO flightClassTypeDAO = new HibernateFlightClassTypeDAO();

    public FlightClassTypeService() {
        // empty constructor
    }

    public List<FlightClassType> findAll() throws DAOException {

        try {
            HibernateHelper.beginTransaction();

            List<FlightClassType> flightClassTypes = flightClassTypeDAO.findAll();

            HibernateHelper.commitTransaction();

            return flightClassTypes;
        } catch (DAOException e) {
            HibernateHelper.rollbackTransaction();

            throw e;
        }
    }
}
